package com.atguigu.Controller;

import com.atguigu.Serivce.EmployeeService;
import com.atguigu.Utils.R;
import com.atguigu.pojo.Employee;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("employee")
@Slf4j
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 管理员登录
     * 使用token比较好但前端没有做解析token
     * @param employee
     * @return
     */
    @PostMapping("login")
    public R<Employee> login(HttpServletRequest request, @RequestBody Employee employee) {
        return employeeService.login(request,employee);
    }

    @PostMapping("logout")
    public R logout(HttpServletRequest request) {
        return employeeService.logout(request);
    }

    @PostMapping
    public R addEmployee(HttpServletRequest request,@RequestBody Employee employee) {
        log.info("当前线程Id："+Thread.currentThread().getId());
        return employeeService.addEmployee(request,employee);
    }

    @GetMapping("page")
    public R<Page<Employee>> page(Integer page,Integer pageSize,String name){

        return employeeService.page(page,pageSize,name);
    }

    @PutMapping
    public R updateEmployee(HttpServletRequest request,@RequestBody Employee employee) {
      return employeeService.updateEmployee(request,employee);
    }

    @GetMapping("{id}")
    public R reCheck(HttpServletRequest request,@PathVariable Long id) {
        return employeeService.reCheck(request, id);
    }


}
